import 'package:flutter/material.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/custom/load_image.dart';
import 'package:flutter_juwo/ui/pages/personalCenterPages/inforPages/initAccount/model/platform_entity.dart';
import 'package:flutter_juwo/ui/res/gaps.dart';

import 'base_dialog.dart';

/// design/7店铺-店铺配置/index.html#artboard10
class PlatformDialog extends StatefulWidget {
  PlatformDialog({
    Key key,
    this.value,
    this.onPressed,
    this.platformEntity,
  }) : super(key: key);

  final int value;
  final PlatformEntity platformEntity;
  final Function(int) onPressed;

  @override
  _PayTypeDialog createState() => _PayTypeDialog();
}

class _PayTypeDialog extends State<PlatformDialog> {
  int _selectValue = 0;
  var _list = [];

  Widget getItem(int index) {
    return Material(
      type: MaterialType.transparency,
      child: InkWell(
        child: SizedBox(
          height: 42.0,
          child: Row(
            children: <Widget>[
              Gaps.hGap16,
              UiUtils.cachedNetworkImage(
                  30, 30, widget.platformEntity.data[index].picture),
              Expanded(
                child:Container(
                  margin: EdgeInsets.only(left: ScreenUtil().setWidth(15)),
                  child:  Text(
                    _list[index],
                    style: TextStyles.custom(
                        26, Colours.appC1, Font.PingFangMedium),
                  ),
                ),
              ),
              LoadAssetImage(_selectValue == index ? "xz" : "xztm",
                  width: 16.0, height: 16.0),
              Gaps.hGap16,
            ],
          ),
        ),
        onTap: () {
          print("index:$index");
          setState(() {
            _selectValue = index;
          });
        },
      ),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _selectValue = widget.value;
    for (int i = 0; i < widget.platformEntity.data.length; i++) {
      _list.add(widget.platformEntity.data[i].name);
    }
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> widgets = [];
    for (int i = 0; i < _list.length; i++) {
      widgets.add(getItem(i));
    }

    return BaseDialog(
      title: "选择电商类别",
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        mainAxisSize: MainAxisSize.min,
        children: widgets,
      ),
      onPressed: () {
        NavigatorUtils.goBack(context);
        widget.onPressed(_selectValue);
      },
      onCancle: (){
        NavigatorUtils.goBack(context);
      },
    );
  }
}
